package com.atguigu.tingshu.account.mapper;

import com.atguigu.tingshu.model.account.UserAccount;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;

@Mapper
public interface UserAccountMapper extends BaseMapper<UserAccount> {


    /**、
     * 修改账户余额
     */
    @Update("update user_account set total_amount = total_amount -#{amount} ,  available_amount =available_amount -#{amount}\n" +
            "                                           , total_pay_amount =total_pay_amount +#{amount}\n" +
            "        where user_id =#{userId} and available_amount >=#{amount};")
    int updateCheckAndDeduct(@Param("userId") Long userId, @Param("amount") BigDecimal amount);

    /**
     * 钱包余额充值
     * @param userId
     * @param
     * @return
     */
    int add(@Param("userId") Long userId, @Param("amount") BigDecimal amount);
}
